﻿rem
	####################################################################
	
	OIS 
	
	####################################################################
endrem
SuperStrict

rem
bbdoc: SEDM.ois
endrem
Module sedm.OIS

ModuleInfo "Name: sedm.ois"
ModuleInfo "Description: Wrapper for OIS (Open Input System)"
ModuleInfo "Licence: OIS License"
ModuleInfo "Author: Jens [bruZard] Henschel"

Import "bOIS.lib"

Extern "win32"
	Function createInputManager:Byte ptr(hWnd:Int)
	Function createKeyboardHandler:Byte ptr(inputmanager:Byte ptr)
	Function createMouseHandler:Byte ptr(inpputmanager:Byte ptr, windowWidth:Int, windowHeight:Int)
	Function captureKeyboard(keyboardhandler:Byte ptr)
	Function captureMouse(MouseHandler:Byte ptr)
	Function isKeyDown:Byte(keyboardhandler:Byte ptr, keycode:Int)
	Function isMouseDown:Byte(MouseHandler:Byte ptr, button:Int)
	Function getRelMouseX:Int(MouseHandler:Byte ptr)
	Function getRelMouseY:Int(MouseHandler:Byte ptr)
	Function getAbsMouseX:Int(MouseHandler:Byte ptr)
	Function getAbsMouseY:Int(MouseHandler:Byte ptr)
End Extern


Type TOIS
	Field inputhandler:Byte ptr
	Field mouse:Byte ptr
	Field keyb:Byte ptr
	
	Function Init:TOIS(hWnd:Int, windowWidth:Int, windowHeight:Int)
		If hWnd = 0 Then Return Null
		Local i:TOIS 	= New TOIS
		i.inputhandler	= createInputManager(hWnd)
		i.mouse			= createMouseHandler(i.inputhandler, windowWidth, windowHeight)
		i.keyb			= createKeyboardHandler(i.inputhandler)
		
		Return i
	End Function
	
	
	Method Update()
		captureMouse(Self.mouse)
		captureKeyboard(Self.keyb)
	End Method
	
	
	Method KeyDown:Byte(keycode:Int)
		Return isKeyDown(Self.keyb, keycode)
	End Method
	
	
	Method MouseDown:Byte(button:Int)
		Return isMouseDown(Self.mouse, button)
	End Method
	
	
	Method MouseX:Int()
		Return getAbsMouseX(Self.mouse)
	End Method
	
	
	Method MouseY:Int()
		Return getAbsMouseY(Self.mouse)
	End Method
	
	
	Method MouseXSpeed:Int()
		Return getRelMouseX(Self.mouse)
	End Method
	
	
	Method MouseYSpeed:Int()
		Return getRelMouseY(Self.mouse)
	End Method
End Type